package com.zjuee.web.ledger.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.base.dto.common.login.LoginDto;
import com.zjuee.base.valid.Insert;
import com.zjuee.base.valid.Update;
import com.zjuee.service.PlanAffairsService;
import com.zjuee.service.PlanService;
import com.zjuee.base.model.common.plan.PlanAffairs;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(Common.Service.ZJUEE_CO_MAIN_PLAN_URL_PREFIX)
public class PlanAffairsController{
    @Resource
    private PlanAffairsService planAffairsService;
    @Resource
    private PlanService planService;
    @Resource
    private LoginDto loginDto;


    /**
     * 新增利用处置设施情况 PlanAffairs
     *
     * @param planAffairs PlanAffairs
     * @return Long
     */
    @PostMapping("/affairs/add")
    public R<Long> addPlanAffairs(@Validated(Insert.class) @RequestBody PlanAffairs planAffairs) {
        if (planAffairs.getWpiId() == null) {
            return R.fail("计划ID为空！");
        }
        return R.ok(planAffairsService.add(planAffairs));
    }
    /**
     * 修改利用处置设施情况 PlanAffairs
     *
     * @param planAffairs PlanAffairs
     * @return Boolean
     */
    public R<Boolean> updatePlanAffairs(@Validated(Update.class) @RequestBody PlanAffairs planAffairs) {
        if (planAffairs.getWpiId() == null) {
            return R.fail("计划ID为空！");
        }
        return R.ok(planAffairsService.update(planAffairs));
    }

//    @Override
//    public R<Boolean> deletePlanAffairs(@NotNull Long id, @NotNull String wpiYear) {
//        Boolean type = false;
//        if (wpiYear.equals(DateUtils.getYear(new Date()))) {
//            type = planAffairsService.delete(id, loginDto.getPlanId());
//        } else {
//            PlanInfo plan = planService.selectInfoByBciId(loginDto.getOrgBusinessId(), wpiYear);
//            if (plan != null) {
//                type = planAffairsService.delete(id, plan.getId());
//            } else {
//                return R.fail("删除自行处置设备情况信息失败");
//            }
//        }
//        if (type) {
//            return R.ok("success");
//        }
//        return R.fail("删除自行处置设备情况信息失败");
//    }
}
